<template>
  <div class="funnel-step">
    <div class="step-top">
      <div class="step-index">Step {{ stepIndex + 1 }}</div>
      <div class="step-content">
        <el-form-item
          :prop="formNm + '.show_lab_column'"
          :rules="{
            required: true,
            message: '步骤名称不能为空',
            trigger: 'blur'
          }"
          class="step-name"
        >
          <el-input v-model="config.show_lab_column" placeholder="输入步骤名称"></el-input>
        </el-form-item>
      </div>
      <el-popover placement="right-start" width="120" trigger="hover" popper-class="tag-group-handler">
        <ul>
          <li @click="addFilter"><i class="el-icon-circle-plus-outline"></i>添加条件</li>
          <li @click="handleDelete">
            <icon-svg name="iconDelete" class="el-delete"></icon-svg>
            删除步骤
          </li>
        </ul>
        <i class="el-icon-more step-handler" slot="reference"></i>
      </el-popover>
    </div>
    <funnel-filter ref="funnelFilter" :config="config" :formNm="formNm"></funnel-filter>
  </div>
</template>

<script>
import funnelFilter from './funnel-filter'
export default {
  components: {
    funnelFilter
  },
  props: {
    config: {
      type: Object,
      required: true,
      default: () => {}
    },
    stepIndex: {
      type: Number,
      default: 0
    },
    formNm: {
      type: String,
      default: 'funnel'
    }
  },
  data() {
    return {}
  },
  methods: {
    handleDelete() {
      this.$confirm('确定删除该步骤？').then(() => this.$emit('deleteStep', this.stepIndex))
    },
    addFilter() {
      this.$refs.funnelFilter.addFilter()
    }
  }
}
</script>

<style lang="scss">
.funnel-step {
  padding: 10px;
  border-bottom: 1px solid #ededed;
  &:hover {
    background-color: #f2f6ff;
  }
  .step-top {
    display: flex;
  }
  .step-index {
    font-weight: bold;
  }
  .step-content {
    flex: 1;
    padding: 0 10px;
    .el-form-item {
      margin-top: -5px;
    }
  }
  .step-handler {
    font-size: 16px;
    color: #6a86cc;
    cursor: pointer;
  }
  .el-form-item {
    margin-bottom: 15px;
  }
  .el-form-item__content {
    line-height: normal;
  }
  .el-form-item__label {
    font-size: 12px;
    color: #6a86cc;
  }
  .el-form-item__error {
    padding-top: 2px;
  }
  .step-name {
    height: 28px;
    line-height: 28px;
    .el-form-item__label {
      line-height: 28px;
    }
    .el-input__inner {
      height: 28px;
      line-height: 28px;
      color: #6a86cc;
      background-color: #e6eeff;
      &:hover {
        border-color: #6a86cc;
      }
    }
  }
}
</style>
